import { defineStore } from "pinia";
import { store } from "@/store";

type setType = {
  activeName: string;
  baseInfo: {
    icon: string;
    name: string;
    tag_list: string;
    specification_list: string;
    third_value: string;
    note: string;
    publish_status: string;
    is_effective: string;

    // formula_subid: string;
    // formula_version: string;
    // material_list: string;
    // formula_detail: string;
    // version: string;
  };
  materialIds: Array<any>;
  specList: Array<any>;
  formulaDetail: Array<any>;
  materialList: Array<any>;
};
export const useCabinetStore = defineStore({
  id: "cabinet",
  state: (): setType => ({
    activeName: "",
    baseInfo: {
      icon: "", // 配方主图
      name: "", // 配方名称
      tag_list: "", // 配方标签
      specification_list: "", // 可选规格
      third_value: "", // 外部ID
      note: "", // 备注
      publish_status: "1",
      is_effective: ""

      // formula_subid: "",
      // formula_version: "",
      // material_list: "",
      // formula_detail: "",
      // version: ""
    },
    materialIds: [],
    materialList: [],
    specList: [],
    formulaDetail: []
  }),
  getters: {
    getBaseInfo(state) {
      return state.baseInfo;
    },
    getActiveName(state) {
      return state.activeName;
    },
    getMaterialIds(state) {
      return state.materialIds;
    },
    getMaterialList(state) {
      return state.materialList;
    },
    getSpecList(state) {
      return state.specList;
    },
    getFormulaDetail(state) {
      return state.formulaDetail;
    }
  },
  actions: {
    changeBaseInfo(data) {
      this.baseInfo = data;
    },
    changeActiveName(data) {
      this.activeName = data;
    },
    changeMaterialIds(data) {
      this.materialIds = data;
    },
    changeMaterialList(data) {
      this.materialList = data;
    },
    changeSpecList(data) {
      this.specList = data;
    },
    changeFormulaDetail(data) {
      this.formulaDetail = data;
    },
    clearState() {
      this.$reset();
    }
  }
});

export function useSettingStoreHook() {
  return useCabinetStore(store);
}
